//
//  ViewExtend.swift
//  FramerSwift
//
//  Created by ym on 16/3/20.
//  Copyright © 2016年 ym. All rights reserved.
//

import UIKit

extension UIView {
    var x:CGFloat!{
        get {
            return frame.origin.x
        }
        set(value){
            frame.origin.x = value
        }
    }
    
    var y:CGFloat!{
        get {
            return frame.origin.y
        }
        set(value){
            frame.origin.y = value
        }
    }
    
    var z:CGFloat!{
        get {
            return frame.origin.y
        }
        set(value){
            frame.origin.y = value
        }
    }
    
    var zPos:CGFloat!{
        get {
            return layer.zPosition
        }
        set(value){
            layer.zPosition = value
        }
    }
    var w:CGFloat! {
        get{
            return frame.width
        }
        set(value){
            frame = CGRectMake(x, y, value, h)
        }
    }
    var h:CGFloat! {
        get{
            return frame.height
        }
        set(value){
            frame = CGRectMake(x, y, w, value)
        }
    }
    var midX:CGFloat! {
        get{
            return frame.width/2.0 + x
        }
        set(value){
            frame.origin.x = value - frame.width/2.0
        }
    }
    var midY:CGFloat! {
        get{
            return frame.height/2.0 + y
        }
        set(value){
            frame.origin.y = value - frame.height/2.0
        }
    }
    var maxX:CGFloat! {
        get{
            return frame.width + x
        }
        set(value){
            frame.origin.x = value - frame.width
        }
    }
    var maxY:CGFloat! {
        get{
            return frame.height + y
        }
        set(value){
            frame.origin.y = value - frame.height
        }
    }
    
    func framer(x:CGFloat, y:CGFloat, w:CGFloat, h:CGFloat) {
        self.frame = CGRectMake(x, y, w, h)
    }
    
    var color:UIColor {
        get {
            return self.backgroundColor!
        }
        set(value){
            self.backgroundColor = value
        }
    }
    
    var anchor:CGPoint {
        get {
            return self.layer.anchorPoint
        }
        set(value) {
            self.layer.anchorPoint = value
        }
    }
    
    var radius:CGFloat {
        get {
            return self.layer.cornerRadius
        }
        set(value) {
            self.layer.cornerRadius = value
        }
    }
    var mask:Bool {
        get {
            return self.layer.masksToBounds
        }
        set(value) {
            self.layer.masksToBounds = value
        }
    }
    var border:CGFloat {
        get {
            return self.layer.borderWidth
        }
        set(value) {
            self.layer.borderWidth = value
//            self.layer.shadowRadius = value
        }
    }
    var borderColor:UIColor {
        get {
            return UIColor(CGColor: self.layer.borderColor!)
        }
        set(value) {
            self.layer.borderColor = value.CGColor
        }
    }
    var shadowSize:CGSize {
        get {
            return self.layer.shadowOffset
        }
        set(value){
            self.layer.shadowOffset = value
        }
    }
    var shadowBlur:CGFloat {
        get {
            return self.layer.shadowRadius
        }
        set(value) {
            self.layer.shadowRadius = value
        }
    }
    var shadowColor:UIColor {
        get {
            return UIColor(CGColor: self.layer.shadowColor!)
        }
        set(value) {
            if(self.layer.shadowOpacity == 0) {
                self.layer.shadowOpacity = 1
            }
            self.layer.shadowColor = value.CGColor
        }
    }
    var scale:CGSize {
        get {
            return self.scale
        }
        set(value) {
            self.transform = CGAffineTransformScale(self.transform, value.width, value.height)
        }
    }
    
//    var rotation:CGFloat
//    var alpha:CGFloat
//    var userInteractionEnabled:Bool
//    var tag:Int
}